using System;
using System.ComponentModel.Composition;
using System.Windows.Forms;

namespace ICP_MS.Plugin.Register;

public class RegisterPlugin : Extension
{
	private FormRegister formRegister = null;

	private const string kRegister = "kRegister";

	[Import("Shell", typeof(ContainerControl))]
	private ContainerControl Shell { get; set; }

	public override void Activate()
	{
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Expected O, but got Unknown
		IHeaderControl header = ((Extension)this).App.HeaderControl;
		IStatusControl status = ((Extension)this).App.StatusControl;
		if (!header.CheckKey("kRegister"))
		{
			header.Add((HeaderItem)new SimpleActionItem("kTool", Lang.Txt("iMass.Menu.Tool.Register.Text"), (EventHandler)Register_Event)
			{
				Key = "kRegister"
			});
		}
		Shell = ((Extension)this).App.Shell;
		((Extension)this).Activate();
	}

	public override void Deactivate()
	{
		((Extension)this).Deactivate();
	}

	private void Register_Event(object sender, EventArgs e)
	{
		if (formRegister == null)
		{
			formRegister = new FormRegister();
			formRegister.MdiParent = Shell as Form;
			formRegister.FormClosed += delegate
			{
				formRegister = null;
			};
			formRegister.Show();
		}
		else
		{
			formRegister.Activate();
			formRegister.BringToFront();
		}
	}
}
